﻿using Abp.Dependency;
using Abp.Events.Bus.Handlers;
using shenghua.Member.Members;
using shenghua.Member.XP.EventDatas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Member.Level
{
    class LevelEventHandler :
        IEventHandler<AfterChangeTotalXPValueEventData>,
        ITransientDependency
    {
        private readonly MemberManager _memberManager;

        public LevelEventHandler(
            MemberManager memberManager
            )
        {
            _memberManager = memberManager;
        }

        public void HandleEvent(AfterChangeTotalXPValueEventData eventData)
        {
            int level = _memberManager.CalculateLevelWithTotalXPValue(eventData.TotalXPValue).Result;
            _memberManager.SetLevel(eventData.MemberId, level, "积分升级").Wait();
        }
    }
}
